package com.hhb.test;

import com.hhb.mapper.UserMapper;
import com.hhb.model.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class Demo05 {

    String resource = "mybatis-config.xml";
    InputStream inputStream = null;
    SqlSession openSession = null;



    @Test
    public void test02()  {


        try {
            inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

            openSession = sqlSessionFactory.openSession();

            UserMapper mapper = openSession.getMapper(UserMapper.class);

            User userAndDept = mapper.findUserAndDept(33);
            System.out.println(userAndDept);
            System.out.println(userAndDept.getDept());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            openSession.close();
        }

    }
}
